package com.ch999.jiujidetect;

import android.Manifest;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;

import com.ch999.baseres.BaseActivity;
import com.github.mzule.activityrouter.annotation.Module;
import com.scorpio.mylib.Routers.MDRouters;

import java.util.Timer;
import java.util.TimerTask;

@Module("main")
public class LoadingActivity extends BaseActivity {

    private Context context;

    /**
     * APP 需要获取的权限控制
     */
    String[] PERMISSIONS = new String[]{Manifest.permission.ACCESS_FINE_LOCATION
            , Manifest.permission.ACCESS_COARSE_LOCATION
            , Manifest.permission.READ_PHONE_STATE
            , Manifest.permission.CAMERA
            , Manifest.permission.WRITE_EXTERNAL_STORAGE
    };


    @Override
    public void findViewById() {

    }

    @Override
    public void setUp() {

    }

    @Override
    public void refreshView() {

    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_loading);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
        }
        final FrameLayout tvContent = (FrameLayout) findViewById(R.id.conteng);
        final RelativeLayout rlImage = (RelativeLayout) findViewById(R.id.rl_img);
        new AppVersionsInfo(this).setListenter(new AppVersionsInfo.AppVersionEvents() {
            @Override
            public void OAA_pp() {

            }

            @Override
            public void ZhongYou_App() {
                tvContent.setBackgroundResource(R.mipmap.ic_loading_page_express);
                rlImage.setVisibility(View.GONE);


            }
        });

//        logo.setImageResource(getMetaDataInt(context, R.));

        context = this;
        nextPage();



    }


    public static int getMetaDataInt(Context context, String name) {
        try {
            ApplicationInfo appInfo = context.getApplicationContext().getPackageManager()
                    .getApplicationInfo(context.getApplicationContext().getPackageName(),
                            PackageManager.GET_META_DATA);
            int logo = appInfo.metaData.getInt(name);
            return logo;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return -1;
    }

    private void nextPage() {
        Timer timer = new Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {

                Bundle bundle = new Bundle();
                bundle.putString("isApp", "false");//集成主站使用true，revaluation
                bundle.putString("appname", getResources().getString(R.string.app_name));//集成主站使用true，revaluation
                bundle.putString("apikey", getResources().getString(R.string.apikey));//集成主站使用true，revaluation
                new MDRouters.Builder().build("jiuji://revaluation").bind(bundle).create(context).go();
//                startAnimActivity(MainActivityApp.class);
                overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                finish();


            }
        };
        timer.schedule(timerTask, 1000);
    }

}
